cd "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19"
use "Donnees\pit\instru2017R21.dta", clear
drop if ze=="9306" | ze=="9109" | ze=="9110" | ze=="9116" | ze=="8307" | ze=="7206" | ze=="5214" 
drop if ze=="4101" | ze=="4111" | ze=="8306"
xi, pre(Y_) i.an*lsconst i.an*lstrad i.an*lsntrad i.an*lzepop
drop if an==1968
drop if an==1976

/*browse ze if missing(dimm75)*/
drop if missing(dimm75)

gen reg=substr(ze,1,2)
gen nreg="11" if reg=="11" | reg=="00"
replace nreg="24" if reg=="24"
replace nreg="27" if reg=="26" | reg=="43"
replace nreg="28" if reg=="23" | reg=="25"
replace nreg="32" if reg=="31" | reg=="22"
replace nreg="44" if reg=="42" | reg=="21" | reg=="41"
replace nreg="52" if reg=="52" 
replace nreg="53" if reg=="53" 
replace nreg="75" if reg=="72" | reg=="74" | reg=="54"
replace nreg="76" if reg=="91" | reg=="73"
replace nreg="84" if reg=="83" | reg=="82"
replace nreg="93" if reg=="93" 
replace nreg="94" if reg=="94" 

xi , pre(REG_) i.nreg

/* TABLE 3 PANEL A */
ivreg2 dimm dimm75 Y_* , cl(ze) partial(Y_* )
estimates store c1
ivreg2 dimm dimm75 Y_* REG_*, cl(ze) partial(Y_* REG_*)
estimates store c2
ivreg2 dimm dimm75 ldimm75 Y_* REG_*, cl(ze) partial(Y_* REG_*)
estimates store c3
ivreg2 dimm dimtm2 Y_* , cl(ze) partial(Y_* )
estimates store c4
ivreg2 dimm dimtm2 Y_* REG_*, cl(ze) partial(Y_* REG_*)
estimates store c5
ivreg2 dimm dimtm2 ldimtm2 Y_* REG_*, cl(ze) partial(Y_* REG_*)
estimates store c6
estout c1 c2 c3 c4 c5 c6, cells(b(star fmt(%9.3f)) ///
se(par(`"="("'`")""'))) stats(N r2 ) starlevels(* 0.10 ** 0.05 *** 0.01)

/* first stage fisher TABLE 3 PANEL A */
ivreg2 zepop (dimm = dimm75) Y_* , cl(ze) partial(Y_* )
ivreg2 zepop (dimm = dimm75) Y_* REG_*, cl(ze) partial(Y_* REG_*)
ivreg2 zepop (dimm = dimm75 ldimm75) Y_* REG_*, cl(ze) partial(Y_* REG_*)
ivreg2 zepop (dimm = dimtm2) Y_* , cl(ze) partial(Y_* )
ivreg2 zepop (dimm = dimtm2) Y_* REG_*, cl(ze) partial(Y_* REG_*)
ivreg2 zepop (dimm = dimtm2 ldimtm2) Y_* REG_*, cl(ze) partial(Y_* REG_*)

/* TABLE 3 PANEL B */
ivreg2 dimm dimm75 ldimm75 if an==1982  , cl(ze) 
estimates store c82
ivreg2 dimm dimm75 ldimm75 if an==1991 , cl(ze) 
estimates store c91
ivreg2 dimm dimm75 ldimm75 if an==1999 , cl(ze) 
estimates store c99
ivreg2 dimm dimm75 ldimm75 if an==2007  , cl(ze) 
estimates store c07
estout c82 c91 c99 c07, cells(b(star fmt(%9.3f)) ///
se(par(`"="("'`")""'))) stats(N r2 rkf) starlevels(* 0.10 ** 0.05 *** 0.01)

/* first stage fisher */
ivreg2 zepop (dimm = dimm75 ldimm75) if an==1982 , cl(ze) 
ivreg2 zepop (dimm = dimm75 ldimm75) if an==1991 , cl(ze) 
ivreg2 zepop (dimm = dimm75 ldimm75) if an==1999 , cl(ze) 
ivreg2 zepop (dimm = dimm75 ldimm75) if an==2007 , cl(ze) 

/* TABLE 3 PANEL C */
ivreg2 dimm dimtm2 ldimtm2 if an==1982  , cl(ze) 
estimates store c82
ivreg2 dimm dimtm2 ldimtm2 if an==1991 , cl(ze) 
estimates store c91
ivreg2 dimm dimtm2 ldimtm2 if an==1999 , cl(ze) 
estimates store c99
ivreg2 dimm dimtm2 ldimtm2 if an==2007  , cl(ze) 
estimates store c07
estout c82 c91 c99 c07, cells(b(star fmt(%9.3f)) ///
se(par(`"="("'`")""'))) stats(N r2 rkf) starlevels(* 0.10 ** 0.05 *** 0.01)

/* first stage fisher */
ivreg2 zepop (dimm = dimtm2 ldimtm2 ) if an==1982 , cl(ze) 
ivreg2 zepop (dimm = dimtm2 ldimtm2 ) if an==1991 , cl(ze) 
ivreg2 zepop (dimm = dimtm2 ldimtm2 ) if an==1999 , cl(ze) 
ivreg2 zepop (dimm = dimtm2 ldimtm2 ) if an==2007 , cl(ze) 
